﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BanditGame2.WCFService;

namespace BanditGame2
{
    public partial class Menu : UserControl
    {
        public Menu()
        {
            InitializeComponent();
            WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
            WCFClient.getUserFullNameCompleted += new EventHandler<getUserFullNameCompletedEventArgs>(getUserFullName);
            WCFClient.getUserFullNameAsync(App.currentUserLogin);
        }

        private void getUserFullName(object sender, getUserFullNameCompletedEventArgs e)
        {
            tbLoggedUser.Text = ("Vítejte " + e.Result);
        }

        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            SetBackGroundDimensions();
        }

        private void SetBackGroundDimensions()
        {
            grdLayoutRoot.Width = BrowserScreenInformation.ClientWidth;
            grdLayoutRoot.Height = BrowserScreenInformation.ClientHeight;
        }

        private void btnNewGame_Click(object sender, RoutedEventArgs e)
        {
            PageSwitcher pageSwticher = (PageSwitcher)this.Parent;
            pageSwticher.Navigate(new MainPage(1));
        }

        private void btnPasswordChange_Click(object sender, RoutedEventArgs e)
        {
            ChangeUserDetailsWindow changeUserDetailsWindow = new ChangeUserDetailsWindow();
            changeUserDetailsWindow.Show();
            changeUserDetailsWindow.Closed += delegate
            {
                var result = changeUserDetailsWindow.DialogResult;
                //Pokud je odpoved spravna
                if (result == true)
                {
                    WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
                    WCFClient.getUserFullNameCompleted += new EventHandler<getUserFullNameCompletedEventArgs>(getUserFullName);
                    WCFClient.getUserFullNameAsync(App.currentUserLogin);
                }
            };
        }

        private void btnLogOff_Click(object sender, RoutedEventArgs e)
        {
            PageSwitcher pageSwticher = (PageSwitcher)this.Parent;
            App.currentUserLogin = null;
            pageSwticher.Navigate(new LoginScreen());
        }

        private void btnScore_Click(object sender, RoutedEventArgs e)
        {
            ScoreWindow scoreWindow = new ScoreWindow();
            scoreWindow.Show();
        }
    }
}
